<?php

// +----------------------------------------------------------------------
// | Theme api控制器
// +----------------------------------------------------------------------
// | @author fancsen
// +----------------------------------------------------------------------

/**
 * Banner api控制器
 * @author fancsen
 */


namespace app\api\controller\v1;

use app\api\model\Theme as ThemeModel;
use app\common\lib\exception\ApiException;
use app\api\validate\IDCollection;
use app\api\validate\IDMustBePostiveInt;

class Theme
{
   
    /**
    * 获取专题推荐
    * @http get  /theme?ids=1,2,3 
    * @param string ids 
    * @return array 返回一组theme
    */
    public function getSimpleList($ids='')
    {
        (new IDCollection())->goCheck();

        $themes = ThemeModel::getThemesByIds($ids);

        if($themes->isEmpty()){
            throw new ApiException('请求的themes不存在',404,30000);
        }
        return show(config('api.success_status'),'ok',$themes);
    }
    /**
    * 获取专题详情
    * @http get  /theme/id=1 
    * @param string theme id 
    * @return array 返回一组theme下的products
    */
    public function getComplexOne($id)
    {
        (new IDMustBePostiveInt())->goCheck();

        $themes = ThemeModel::getThemeWithProducts($id);
        if(!$themes){
            throw new ApiException('请求的theme不存在',404,30000);
        }
        return show(config('api.success_status'),'ok',$themes);
    }

}